package test;

public class Demo3 {

    public static volatile boolean flag;

    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(() -> {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

            flag = true;
            System.out.println(flag);
        });

        thread.start();

        method();
    }

    public static void method() {
        int count = 0;

        while (!flag) {
            count++;
        }

        System.out.println("while stop");
    }
}
